package com.gilgamesh.mall.product.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gilgamesh.mall.product.sql.ClassficSql;
import com.gilgamesh.mall.sdk.bean.product.ClassficEntity;
import com.gilgamesh.mall.sdk.dto.product.ClassficDTO;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import java.util.List;

/**
 * @author yanm
 * @date 2021/1/11 14:14
 **/
@Mapper
public interface ClassficDao extends BaseMapper<ClassficEntity> {

    @Results(
            id = "classifcDTOMap",value = {
            @Result(column = "id" ,jdbcType = JdbcType.BIGINT,javaType = java.lang.Long.class,property = "id"),
            @Result(column = "classfic_name" ,jdbcType = JdbcType.VARCHAR,javaType = java.lang.String.class,property = "classficName"),
            @Result(column = "level",jdbcType = JdbcType.TINYINT,javaType = java.lang.Byte.class,property = "level"),
            @Result(column = "superior_id",jdbcType = JdbcType.BIGINT,javaType = java.lang.Long.class,property = "superiorId"),
            @Result(column = "create_time",jdbcType = JdbcType.DATETIMEOFFSET,javaType = java.util.Date.class,property = "createTime"),
            @Result(column = "rank",jdbcType = JdbcType.TINYINT,javaType = java.lang.Byte.class,property = "rank")
    }
    )
    @SelectProvider(type = ClassficSql.class , method = "listClassfics")
    List<ClassficDTO> listClassfics(ClassficEntity entity);

    @Select("select * from t_classfic where id =#{id}")
    ClassficDTO getById(Long id);


   @Insert("insert into t_classfic(`id`,`classfic_name`,`level`,`superior_id`,`create_time`,`rank`)  VALUES  (#{id}, #{classficName}, #{level}, #{superiorId}, #{createTime}, #{rank})")
   int add(ClassficEntity entity);


    @Select("select * from `t_classfic` where `level` = 3 and `classfic_name` like   CONCAT('%',#{classficName},'%')")
    List<ClassficDTO> listByKeyWord(String classficName);
}
